﻿using System;
using System.Drawing;
using System.Windows.Forms;
using GraphicLibrary;
using CSML;
using FFTLibrary;
using Lab4.Forms;
using System.Threading;

namespace Lab4
{
    public partial class FFTTime : Form
    {
        private Complex[] transformResult;
        
        public FFTTime()
        {
            InitializeComponent();
            ParameterForm lab4start = new ParameterForm();
            lab4start.Owner = this;
            lab4start.Show();
            this.Hide();
        }

        private void FFTTime_Load(object sender, EventArgs e)
        {
          

           
        }

        public void LoadForm(int l)
        {
            this.Show();
            Signal signal = new Signal();
            int n = (int)Math.Pow(2, l);
            double[] x = signal.GetExpSignal(0,4,n);
            FFTTimeAlgorithm alg = new FFTTimeAlgorithm();
            double[] amplitudes = alg.GetAmplitude(x);
            double[] phases = alg.GetPhase(x);
            transformResult = alg.MakeTransformation(x);
            
            MyChart chartSignal= new MyChart(new Point(15,15));
            MyChart chartAmplitude = new MyChart(new Point(15, 30 + MyChart.chartHeight));
            MyChart chartPhase = new MyChart(new Point(15, 45 + 2 * MyChart.chartHeight));

            chartSignal.InitializeChart(chartSignal, "t", "x(t)", "входной сигнал");
            chartAmplitude.InitializeChart(chartAmplitude, "k", "A(k)", "амплитуды");
            chartPhase.InitializeChart(chartPhase, "k", "P(k)", "фазы");


            // Add the random data.
            chartSignal.SeriesCollection.Add(MyChart.GetSeriesCollection(x));
            chartAmplitude.SeriesCollection.Add(MyChart.GetSeriesCollection(amplitudes));
            chartPhase.SeriesCollection.Add(MyChart.GetSeriesCollection(phases));
            Controls.Add(chartSignal);
            Controls.Add(chartAmplitude);
            Controls.Add(chartPhase);
        }


        private void showData_Click(object sender, EventArgs e)
        {
            DataForm form = new DataForm(transformResult);
            form.Owner = this;
            form.Show();
        }

  
    }
}